import { LoginApi } from "@/api/user"
import { getToken, setToken, delToken } from "@/utils/storage"
export default {
  state () {
    return {
      token: getToken(),
    }
  },
  mutations: {
    changeToken (state, token) {
      state.token = token
    },
    resetToken (state) {
      state.token = null
      delToken()
    }
  },
  actions: {
    async login ({ commit }, ruleForm) {
      const res = await LoginApi(ruleForm)
      // console.log(res.data.token, 1111)

      commit('changeToken', res.data.token)
      setToken(res.data.token)

    }
  },
  getters: {},
  namespaced: true
}